<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no"/>
    <meta name="description" content=""  />
    <title>列表</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script type="application/javascript">
        var prefix = "/api";
        $(function () {
            $('.delete_item').click(function () {
                var value = $(this).attr('value');
                console.log(value);
                $.ajax({
                    type: 'POST',
                    data: {
                        id:value
                    },
                    url: prefix + "/link/source/delete",
                    success: function(){
                        window.location.reload();
                    }
                });
            });

            $('.use_item').click(function () {
                var linkId = $('.linkId').text();
                var value = $(this).attr('value');
                console.log(value);
                $.ajax({
                    type: 'POST',
                    data: {
                        sourceId:value,
                        id:linkId
                    },
                    url: prefix + "/link/updateBySource",
                    success: function(data){
                        console.log(data);
                        alert(data.body);
                    }
                });
            });

            $('.addLink').click(function () {
                var linkId = $('.linkId').text();
                window.location.href = prefix + "/link/source/add/web?linkId=" + linkId;
            });
        });
    </script>
</head>
<body>
<div id="main">
    <div>
        <div style="float: left">id：<span class="linkId" th:text="${linkId}"></span></div>
        <div style="margin-right: 10px; float: right"><a class="addLink" href="#">添加</a></div>
        <div style="clear: both"></div>
    </div>
    <ul>
        <li th:each="collect: ${linkSources}">
            <span style="word-wrap: break-word; word-break: normal;" th:text="${collect.source}"></span>
            <a class="use_item" th:value="${collect.id}" href="#">使用</a>
            <a class="delete_item" th:value="${collect.id}" href="#">删除</a>
        </li>
    </ul>
</div>
</body>
</html>